package com.dome.controller;

import com.dome.common.result.JsonResult;
import com.dome.pojo.redis.vo.TokenVo;
import com.dome.serice.TokenService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 描述：
 *
 * @author tangshunkai
 * @Date 2022/4/26 15:56
 */

@RestController
public class SSOController {

    String name = "admin";

    String pwd = "admin";

    @Autowired
    private TokenService tokenService;

    @RequestMapping("loginToken")
    public JsonResult loginToken(@RequestBody Map<String,String> map){

        if(StringUtils.isBlank(map.get("name"))) return JsonResult.failCodeMessage("400","name is null");
        if(StringUtils.isBlank(map.get("pwd"))) return JsonResult.failCodeMessage("400","pwd is null");

        if(name.equals(map.get("name")) && pwd.equals(map.get("pwd"))){
            TokenVo token = tokenService.createToken(name);
            return JsonResult.success(token);
        }else {
            return JsonResult.failMessage("userName Or Password Is Wrong");
        }
    }
}
